clear all;
clc;
%%
% Hochrechnung auf eine Sekunde Bestrahlung (Soll: 10^16 Photonen)
simfaktor = 1e11;
nDiv = 400;
nDivX = nDiv;
nDivY = nDiv;

%%
if(exist('filename', 'var') == 0)
    [filename, pathname] = uigetfile('.log');
    file = fopen(fullfile(pathname, filename), 'r');

    % Name (xCoord*nDivY+yCoord) eDeposit
    input = fscanf(file,'%u\t%e\n',[2 inf]);
    
    % Bitte daran denken das File zu schliessen, sonst gibt es Probleme
    fclose(file);
end

cells = nDivX*nDivY;
matrix2D = zeros(nDivX, nDivY);

for n=1:numel(input(1,:))
    nx = floor(input(1,n) / nDivY);
    ny = floor((input(1,n) - nx*nDivY));
    matrix2D(nx+1, ny+1) = input(2,n);
end
matrix2D = matrix2D .* simfaktor;

clear input;
%%
% Figure Properties setzen
fig = figure('Position', [0, 0, 800, 664]);
load cmap;
colormap(cmap);
set(gca, 'XLim', [1 nDivX]);
set(gca, 'YLim', [1 nDivY]);

clim = [1e-1 1e2]*simfaktor;

% Logarithmischer Plot (Matlab ausgetrickst)
linear_axes = subplot(1,1,1);
lin_plot = pcolor(linear_axes, matrix2D);

set(gca, 'CLim', clim);
colorbar('Yscale', 'log');

set(linear_axes, 'Visible', 'off');
set(lin_plot, 'Visible', 'off');

log_axes = axes('Position', get(linear_axes, 'Position'));
log_plot = pcolor(log_axes, log10(matrix2D));
set(log_plot, 'EdgeColor','none');
set(gca, 'CLim', log10(clim));
    
axis square tight;
title('Energy Distribution after Lead Plate (eV)');

